AbyssInt = {}
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_modules/cl_usermessages.lua" )
include( 'shared.lua' )
include( 'sv_modules/sv_usermessages.lua' )
include( 'sv_modules/sv_salary.lua' )
include( 'sv_moneystuff.lua' )

// Serverside only stuff goes here

// Some writing/reading functions for text/SQL

function GM:PlayerInitialSpawn( ply ) //"When the player first joins the server and spawns" function 
	// to make sure the first time someone joined it gives them their values.
	if ply:GetPData("cash") == nil and ply:GetPData("bank") == nil then
		ply:SetPData("cash", 500)
		ply:SetPData("bank", 100)
	end
	 ply:SavePlayerData()
	 ply:LoadPlayerData()
		ply:ConCommand( "team_menu" ) //Run the console command when the player first spawns 
		timer.Create("GiveSalary", 300, 0, function(ply)
			for k,v in pairs(player.GetAll()) do
				v:Salary()
		end
	end)
 end
 
function GM:PlayerDeath( victim, weapon, killer )
if victim != killer and ValidEntity(killer) and killer:IsPlayer() and (victim:Team() == 2) or (victim:Team() == 8) then
evolve:Notify(evolve.colors.white, "Officer ", evolve.colors.blue, victim:GetName(), evolve.colors.white, " has been killed by ", evolve.colors.red, killer:GetName())
end
end
 
function GM:OnPlayerChat( ply, txt, teamchat, dead )
	if ( table.Count( evolve.ranks ) > 0 and GAMEMODE.Name == "Sandbox" ) then
		local tab = {}

		if ( dead ) then
			table.insert( tab, Color( 255, 30, 40 ) )
			table.insert( tab, "*DEAD* " )
		end

		if ( teamchat ) then
			table.insert( tab, Color( 30, 160, 40 ) )
			table.insert( tab, "(TEAM) " )
		end

		if ( LocalPlayer():EV_HasPrivilege( "See chat tags" ) and ply:EV_GetRank() != "guest" ) then
			table.insert( tab, color_white )
			table.insert( tab, "(" .. evolve.ranks[ ply:EV_GetRank() ].Title .. ") " )
		end

		if ( IsValid( ply ) ) then
			table.insert( tab, team.GetColor( ply:Team() ) )
			table.insert( tab, ply:Nick() )
		else
			table.insert( tab, "Console" )
		end

		table.insert( tab, Color( 255, 255, 255 ) )
		table.insert( tab, ": " .. txt )

		chat.AddText( unpack( tab ) )

		return true
	end
end
 
 function GM:PlayerSpawn( ply )

    // Call item loadout function
    hook.Call( "PlayerLoadout", GAMEMODE, ply )
    
    // Set player model
    hook.Call( "PlayerSetModel", GAMEMODE, ply )
    
end
 
function GM:ShowSpare2( ply )

    ply:ConCommand( "team_menu" )
    
end

/*---------------------------------------------------------
   Name: gamemode:PlayerLoadout( )
   Desc: Give the player the default spawning weapons/ammo
---------------------------------------------------------*/
function GM:PlayerLoadout( ply )

	ply:StripWeapons() -- This command strips all weapons from the player.
	
if not ( ply.EV_Jailed ) then

if ply:Team() == 1 then

    ply:Give( "weapon_physcannon" ) --Give the player the Gravity Gun
	ply:Give( "weapon_physgun" )
	//ply:Give( "gmod_camera" )
	ply:Give( "weapon_keys" )
 
elseif ply:Team() == 2 then

    ply:Give( "weapon_physcannon" ) --Give the player the Gravity Gun
	ply:Give( "weapon_physgun" )
	ply:Give( "arrest_stick" )
	ply:Give( "lee_cs_glock-burst" )
	ply:Give( "lee_cs_mp5" )
	ply:Give( "unarrest_stick" )
	//ply:Give( "gmod_camera" )
	ply:Give( "weapon_keys" )
 
elseif ply:Team() == 3 then

	ply:Give( "weapon_physcannon" ) --Give the player the Gravity Gun
	ply:Give( "weapon_physgun" )
	//ply:Give( "gmod_camera" )
	ply:Give( "weapon_keys" )
 
elseif ply:Team() == 4 then

	ply:Give( "weapon_physcannon" ) --Give the player the Gravity Gun
	ply:Give( "weapon_physgun" )
	//ply:Give( "gmod_camera" )
	ply:Give( "weapon_keys" )
 
 elseif ply:Team() == 5 then

    ply:Give( "weapon_physcannon" ) --Give the player the Gravity Gun
	ply:Give( "weapon_physgun" )
	ply:Give( "lee_cs_scout" )
	//ply:Give( "gmod_camera" )
	ply:Give( "weapon_keys" )
 
 elseif ply:Team() == 6 then

    ply:Give( "weapon_physcannon" ) --Give the player the Gravity Gun
	ply:Give( "weapon_physgun" )
	//ply:Give( "gmod_camera" )
	ply:Give( "weapon_keys" )
	ply:Give( "weapon_crowbar" )
	
 elseif ply:Team() == 7 then

    ply:Give( "weapon_physcannon" ) --Give the player the Gravity Gun
	ply:Give( "weapon_physgun" )
	ply:Give( "weapon_archercrossbow" )
	ply:Give( "climb_swepnogrip" )
	//ply:Give( "gmod_camera" )
	ply:Give( "weapon_keys" )
	
 elseif ply:Team() == 8 then

    ply:Give( "weapon_physcannon" ) --Give the player the Gravity Gun
	ply:Give( "weapon_physgun" )
	ply:Give( "arrest_stick" )
	ply:Give( "lee_cs_deagle" )
	ply:Give( "lee_cs_m4a1" )
	ply:Give( "unarrest_stick" )
	//ply:Give( "gmod_camera" )
	ply:Give( "weapon_keys" )
	ply:Give( "weapon_slam" )
 
end
end
end

function GM:PlayerSetModel( ply )
	
	if ply:Team() == 1 then
    local modelname = "models/player/group01/male_0".. math.random(1,9) ..".mdl"
    util.PrecacheModel( modelname )
    ply:SetModel( modelname )
	
	elseif ply:Team() == 2 then
	local modelname = "models/player/police.mdl"
    util.PrecacheModel( modelname )
    ply:SetModel( modelname )
	
	elseif ply:Team() == 3 then
	local modelname = "models/player/mossman.mdl"
    util.PrecacheModel( modelname )
    ply:SetModel( modelname )
	
	elseif ply:Team() == 4 then
	local modelname = "models/player/kleiner.mdl"
    util.PrecacheModel( modelname )
    ply:SetModel( modelname )
	
	elseif ply:Team() == 5 then
	local modelname = "models/player/combine_super_soldier.mdl"
    util.PrecacheModel( modelname )
    ply:SetModel( modelname )
	
	elseif ply:Team() == 6 then
	local modelname = "models/player/monk.mdl"
    util.PrecacheModel( modelname )
    ply:SetModel( modelname )
	
	elseif ply:Team() == 7 then
	local modelname = "models/player/group03/male_0".. math.random(1,9) ..".mdl"
    util.PrecacheModel( modelname )
    ply:SetModel( modelname )
	
	elseif ply:Team() == 8 then
	local modelname = "models/player/combine_soldier_prisonguard.mdl"
    util.PrecacheModel( modelname )
    ply:SetModel( modelname )
	
end
    
end

 function team_1( ply ) 
	if ply:Team() == 1 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " You are already a ", Color( 160, 32, 240, 255 ), "citizen", evolve.colors.white, "!")
	else
	evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " has become a ", Color( 160, 32, 240, 255 ), "citizen", evolve.colors.white, ".")
	
    ply:SetTeam( 1 ) //Make the player join team 1
	ply:Spawn()
	end
 end
 
 function team_2( ply ) 
	if ply:Team() == 2 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " You are already a ", Color( 0, 0, 205, 255 ), "police officer", evolve.colors.white, "!")
	else
	evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " has become a ", Color( 0, 0, 205, 255 ), "police officer", evolve.colors.white, ".")
    ply:SetTeam( 2 ) //Make the player join team 2 
	ply:Spawn()
	end
 end

 function team_3( ply ) 
	if ply:Team() == 3 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " You are already an ", Color( 50, 205, 50, 255 ), "accountant", evolve.colors.white, "!")
	else
	evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " has become an ", Color( 50, 205, 50, 255 ), "accountant", evolve.colors.white, ".")
    ply:SetTeam( 3 ) //Make the player join team 3
	ply:Spawn()
	end
 end

 function team_4( ply ) 
	if ply:Team() == 4 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " You are already a ", Color( 255, 165, 0, 255 ), "scientist", evolve.colors.white, "!")
	else
	evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " has become a ", Color( 255, 165, 0, 255 ), "scientist", evolve.colors.white, ".")
    ply:SetTeam( 4 ) //Make the player join team 4
	ply:Spawn()
	end
 end
 function team_5( ply ) 
	if ply:Team() == 5 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " You are already an ", Color( 0, 191, 255, 255 ), "assassin", evolve.colors.white, "!")
	else
	if team.NumPlayers( 5 ) > 1 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " There is already an ", Color( 0, 191, 255, 255 ), "assassin", evolve.colors.white, "!")
	else
	evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " has become an ", Color( 0, 191, 255, 255 ), "assassin", evolve.colors.white, ".")
    ply:SetTeam( 5 ) //Make the player join team 5
	ply:Spawn()
	end
	end
 end
 
 function team_6( ply ) 
	if ply:Team() == 6 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " You are already a ", Color( 160, 82, 45, 255 ), "pedophile", evolve.colors.white, "!")
	else
	evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " has become a ", Color( 160, 82, 45, 255 ), "pedophile", evolve.colors.white, ".")
    ply:SetTeam( 6 ) //Make the player join team 6
	ply:Spawn()
	end
 end
 
 function team_7( ply ) 
	if ply:Team() == 7 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " You are already a ", Color( 255, 255, 255, 255 ), "freerunner", evolve.colors.white, "!")
	else
	evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " has become a ", Color( 255, 255, 255, 255 ), "freerunner", evolve.colors.white, ".")
    ply:SetTeam( 7 ) //Make the player join team 7
	ply:Spawn()
	end
 end
 
 function team_8( ply ) 
	if ply:Team() == 8 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " You are already the ", Color( 160, 32, 240, 255 ), "police chief", evolve.colors.white, "!")
	else
	if team.NumPlayers( 5 ) > 1 then
	evolve:Notify(ply, evolve.colors.red, "ERROR:", evolve.colors.white, " There is already a ", Color( 0, 191, 255, 255 ), "police chief", evolve.colors.white, "!")
	else
	evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " has become the ", Color( 160, 32, 240, 255 ), "police chief", evolve.colors.white, ".")
    ply:SetTeam( 8 ) //Make the player join team 8
	ply:Spawn()
	end
	end
 end
 
 CreateConVar( "rp_jailtime", "120", FCVAR_NOTIFY )
 
 concommand.Add( "team_1", team_1 )
 concommand.Add( "team_2", team_2 )
 concommand.Add( "team_3", team_3 )
 concommand.Add( "team_4", team_4 )
 concommand.Add( "team_5", team_5 )
 concommand.Add( "team_6", team_6 )
 concommand.Add( "team_7", team_7 )
 concommand.Add( "team_8", team_8 )